import request from '../utils/request';

var serverIp = 'http://localhost:8087/'
// var serverIp = '/'


export const fetchData = query => {
    return request({
        url: './table.json',
        method: 'get',
        params: query
    });
};

// 用户登录
export const userLogin = (formData) => {
    return request({
        url: serverIp + 'user/login',
        method: 'post',
        config: {showLoading: true},
        data: formData
    });
};

// 用户注册
export const register = (formData) => {
    return request({
        url: serverIp + 'user/register',
        method: 'post',
        config: {showLoading: true},
        data: formData
    });
};

// 获取菜单
export const getMenu = (formData) => {
    return request({
        url: serverIp + 'menu/getMenu',
        method: 'get',
        config: {showLoading: true}
    });
};

//角色分页查询
export const getRolesPage = (page, size) => {
    return request({
        url: serverIp + 'role/getRolesPage',
        method: 'get',
        config: {showLoading: true},
        params: {
            page: page,
            size: size
        }
    });
};

//查询所有权限
export const getPermission = () => {
    return request({
        url: serverIp + 'permission/getPermission',
        method: 'get',
        config: {showLoading: true}
    });
};

//查询指定角色的拥有的权限
export const getPermissionByRole = (id) => {
    return request({
        url: serverIp + 'permission/getPermissionByRole',
        method: 'get',
        config: {showLoading: true},
        params: {
            id: id
        }
    });
};

//授予权限资源
export const endowPermission = (permissionGroupRoleIdPo) => {
    // var formData = new FormData();
    // formData.append('ids[]',ids);
    // formData.append('roleId',roleId);
    return request({
        url: serverIp + 'permission/endowPermission',
        method: 'post',
        config: {showLoading: true},
        data: permissionGroupRoleIdPo
    });
};

export const getAccounts = (id) => {
    return request({
        url: serverIp + 'admin/user/list',
        method: 'get',
        params: {
            userCommunityId: id
        }
    });
};

export const getHouses = () => {
    return request({
        url: serverIp + 'admin/community/list',
        method: 'get'
    });
};

export const addAccount = (formData) => {
    return request({
        url: serverIp + 'admin/user/insert',
        method: 'post',
        data: formData
    });
};

export const addShop = (formData) => {
    return request({
        url: serverIp + 'admin/store/insert',
        method: 'post',
        data: formData
    });
};

export const updateAccount = (formData) => {
    return request({
        url: serverIp + 'admin/user/update',
        method: 'post',
        data: formData
    });
};

export const delAccount = (formData) => {
    return request({
        url: serverIp + 'admin/user/delete',
        method: 'post',
        data: formData
    });
};

export const updateShop = (formData) => {
    return request({
        url: serverIp + 'admin/store/update',
        method: 'post',
        data: formData
    });
};

export const delShop = (formData) => {
    return request({
        url: serverIp + 'admin/store/delete',
        method: 'post',
        data: formData
    });
};


export const getProducts = (id,name) => {
    return request({
        url: serverIp + 'admin/commodity/list',
        method: 'get',
        params: {
            commodityStoreId: id,
            commodityName: name
        }
    });
};

export const delProduct = (formData) => {
    return request({
        url: serverIp + 'admin/commodity/delete',
        method: 'post',
        data: formData
    });
};

export const getOrders = (id) => {
    return request({
        url: serverIp + 'admin/orderDetail/list',
        method: 'get',
        params: {
            storeId: id
        }
    });
};

export const updateOrder = (formData) => {
    return request({
        url: serverIp + 'admin/orderDetail/update',
        method: 'post',
        data: formData
    });
};

export const getComments = (id) => {
    return request({
        url: serverIp + 'admin/comment/listComment',
        method: 'get',
        params: {
            maintainId: id
        }
    });
};

export const delComment = (formData) => {
    return request({
        url: serverIp + 'admin/comment/delete',
        method: 'post',
        data: formData
    });
};

export const addHouse = (formData) => {
    return request({
        url: serverIp + 'admin/community/insert',
        method: 'post',
        data: formData
    });
};

export const delHouse = (formData) => {
    return request({
        url: serverIp + 'admin/community/delete',
        method: 'post',
        data: formData
    });
};

export const updateHouse = (formData) => {
    return request({
        url: serverIp + 'admin/community/update',
        method: 'post',
        data: formData
    });
};

export const getFunds = (id) => {
    return request({
        url: serverIp + 'admin/fund/list',
        method: 'get',
        params: {
            fund_community_id: id
        }
    });
};

export const getMaintains = (id) => {
    return request({
        url: serverIp + 'admin/maintain/list',
        method: 'get',
        params: {
            maintainCommunityId: id
        }
    });
};

export const getFundById = (id) => {
    return request({
        url: serverIp + 'admin/fund/get',
        method: 'get',
        params: {
            id: id
        }
    });
};

export const addFund = (formData) => {
    return request({
        url: serverIp + 'admin/fund/insert',
        method: 'post',
        data: formData
    });
};

export const updateFund = (formData) => {
    return request({
        url: serverIp + 'admin/fund/update',
        method: 'post',
        data: formData
    });
};

export const updateMaintain = (formData) => {
    return request({
        url: serverIp + 'admin/maintain/update',
        method: 'post',
        data: formData
    });
};

export const delFund = (formData) => {
    return request({
        url: serverIp + 'admin/fund/deleteFund',
        method: 'post',
        data: formData
    });
};

export const delMaintain = (formData) => {
    return request({
        url: serverIp + 'admin/maintain/delete',
        method: 'post',
        data: formData
    });
};

export const getVotes = (id) => {
    return request({
        url: serverIp + 'admin/vote/list',
        method: 'get',
        params: {
            communityId: id
        }
    });
};

export const delVote = (formData) => {
    return request({
        url: serverIp + 'admin/vote/delete',
        method: 'post',
        data: formData
    });
};

export const addVote = (data) => {
    return request({
        url: serverIp + 'admin/vote/insert',
        method: 'post',
        data: data
    });
};

export const getBulletins = (id) => {
    return request({
        url: serverIp + 'admin/notice/list',
        method: 'get',
        params: {
            noticeCommunityId: id
        }
    });
};

export const addBulletin = (formData) => {
    return request({
        url: serverIp + 'admin/notice/insert',
        method: 'post',
        data: formData
    });
};

export const delBulletin = (formData) => {
    return request({
        url: serverIp + 'admin/notice/delete',
        method: 'post',
        data: formData
    });
};

export const maintainAll = () => {
    return request({
        url: serverIp + 'user/maintain/list',
        method: 'get'
    });
};

export const maintainSelf = (id) => {
    return request({
        url: serverIp + 'user/maintain/listSelf',
        method: 'get'
    });
};

export const addUserMaintain = (formData) => {
    return request({
        url: serverIp + 'user/maintain/insert',
        method: 'post',
        data: formData
    });
};

export const delUserMaintain = (formData) => {
    return request({
        url: serverIp + 'user/maintain/delete',
        method: 'post',
        data: formData
    });
};

export const getUserComments = (id) => {
    return request({
        url: serverIp + 'user/comment/listComment',
        method: 'get',
        params: {
            maintainId: id
        }
    });
};

export const usercomment = (formData) => {
    return request({
        url: serverIp + 'user/comment/insert',
        method: 'post',
        data: formData
    });
};

export const userFunds = () => {
    return request({
        url: serverIp + 'user/fund/list',
        method: 'get'
    });
};

export const pay = (formData) => {
    return request({
        url: serverIp + 'user/fundRecord/insert',
        method: 'post',
        data: formData
    });
};

export const userBullentins = () => {
    return request({
        url: serverIp + 'user/notice/list',
        method: 'get'
    });
};

export const userVotes = () => {
    return request({
        url: serverIp + 'user/vote/listVote',
        method: 'get'
    });
};

export const userVoteById = (id) => {
    return request({
        url: serverIp + 'user/vote/getById',
        method: 'get',
        params: {
            voteId: id
        }
    });
};

export const uservote = (formData) => {
    return request({
        url: serverIp + 'user/vote/insert',
        method: 'post',
        data: formData
    });
};

export const charge = (formData) => {
    return request({
        url: serverIp + 'user/recharge',
        method: 'post',
        data: formData
    });
};

export const showInfo = () => {
    return request({
        url: serverIp + 'user/info',
        method: 'get'
    });
};